﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using Oracle.ManagedDataAccess.Client;

namespace ExportToDWGTool
{
    class OrclDBConn
    {
        static public string mstrConn;

        static public OracleConnection OpenConn(string strIP, string strPort, string strServer, string strUserName, string strPassWord)
        {
            OracleConnection conn = null;
            try
            {
                using (conn = new OracleConnection())
                {
                    mstrConn = string.Format("Data Source=(DESCRIPTION="
                + "(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1}))"
                + "(CONNECT_DATA=(SERVICE_NAME={2})));"
                + "User Id={3};Password={4};", strIP, strPort, strServer, strUserName, strPassWord);

                    conn.ConnectionString = mstrConn;

                    conn.Open();

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
           
            return conn;
        }

        static public void CloseConn(OracleConnection conn)
        {
            if (conn == null) { return; }
            try
            {
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                conn.Dispose();
            }
        }


    }
}
